<?php
// +----------------------------
// | Created by PhpStorm
// +----------------------------
// | Author: YnnSon
// +----------------------------
namespace app\api\model;

class Image extends BaseModel
{
    protected $autoWriteTimestamp = true; // 自动写入时间戳

    /**
     * @Desc 插入图片
     *
     * @param $images
     *
     * @return string
     */
    public static function insertImage($images)
    {
        // $images = [
        //     0 => '20200716/d60c883893ebaae40f8c004c83bb870d.jpg',
        //     1 => '20200716/15205c6652cf3c6f4aab623afa0a1719.jpg',
        // ];
        if (is_array($images)) {
            $insertData = [];
            foreach ($images as $image) {
                $insertData[] = ['url' => $image];
            }
            $result = (new self)->saveAll($insertData)->toArray();
            $ids = array_column($result, 'id');
            return implode(',', $ids);
        }
        $result = self::create(['url' => $images]);
        return $result->id;
    }

    public static function updateImage($imageData)
    {
        self::update($imageData);
    }
}